package cn.antho.superhelp.web.controller;

import cn.antho.superhelp.dto.DistributeStaffDto;
import cn.antho.superhelp.dto.ReservationTimeDto;
import cn.antho.superhelp.dto.ReservationDto;
import cn.antho.superhelp.dto.SurveyDto;
import cn.antho.superhelp.service.IReservationService;
import cn.antho.superhelp.domain.Reservation;
import cn.antho.superhelp.query.ReservationQuery;
import cn.antho.superhelp.result.JsonResult;
import cn.antho.superhelp.result.PageList;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reservation")
public class ReservationController {

    @Autowired
    public IReservationService reservationService;

    /**
    * 保存和修改公用的
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JsonResult saveOrUpdate(@RequestBody Reservation reservation){
        if(reservation.getId()!=null){
            reservationService.updateById(reservation);
        }else{
            reservationService.insert(reservation);
        }
        return JsonResult.success();
    }

    /**
    * 删除对象
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JsonResult delete(@PathVariable("id") Long id){
        reservationService.deleteById(id);
        return JsonResult.success();
    }

    /**
   * 获取对象
   */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JsonResult get(@PathVariable("id")Long id){
        return JsonResult.success(reservationService.selectById(id));
    }


    /**
    * 查询所有对象
    */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResult list(){
        return JsonResult.success(reservationService.selectList(null));
    }


    /**
    * 带条件分页查询数据
    */
    @RequestMapping(value = "/pagelist",method = RequestMethod.POST)
    public JsonResult page(@RequestBody ReservationQuery query){
        Page<Reservation> page = new Page<Reservation>(query.getPage(),query.getRows());
        page = reservationService.selectPage(page);
        return JsonResult.success(new PageList<Reservation>(page.getTotal(),page.getRecords()));
    }

    /**
     * 初始化预订单
     * @param reservationDto
     * @return
     */
    @RequestMapping(value = "/initReservation",method = RequestMethod.POST)
    public JsonResult initReservation(@RequestBody ReservationDto reservationDto){
        return reservationService.initReservation(reservationDto);
    }

    /**
     * 分配勘测师
     * @param distributeStaffDto
     * @return
     */
    @RequestMapping(value = "/distributeSurveyor",method = RequestMethod.POST)
    public JsonResult distributeSurveyor(@RequestBody DistributeStaffDto distributeStaffDto){
        return reservationService.distributeSurveyor(distributeStaffDto);
    }

    /**
     * 预约勘测时间
     * @param reservationTimeDto
     * @return
     */
    @RequestMapping(value = "/reservationTime",method = RequestMethod.POST)
    public JsonResult reservationTime(@RequestBody ReservationTimeDto reservationTimeDto){
        return reservationService.reservationTime(reservationTimeDto);
    }

    /**
     * 勘测
     * @param surveyDto
     * @return
     */
    @RequestMapping(value = "/survey",method = RequestMethod.POST)
    public JsonResult survey(@RequestBody SurveyDto surveyDto){
        return reservationService.survey(surveyDto);
    }

}
